#!/bin/sh

# this is for upgraders
addgroup -S -g 23 input 2>/dev/null

# this is for upgraders
if [ -L /etc/runlevels/boot/mdev ] && ! [ -L /etc/runlevels/sysinit/mdev ]; then
	mkdir -p /etc/runlevels/sysinit
	mv /etc/runlevels/boot/mdev /etc/runlevels/sysinit/ 2>/dev/null
fi

rename_service() {
	oldname="$1"
	newname="$2"

	ret=1
	for link in /run/openrc/*/${oldname} /etc/runlevels/*/${oldname}; do
		newlink="${link%/*}/${newname}"
		if [ -L "$link" ] && ! [ -L "$newlink" ]; then
			target="$(readlink $link)"
			ln -s "${target%/*}/$newname" "$newlink"
			rm "$link"
			ret=0
			continue
		fi
		if [ -d "$link" ] && ! [ -d "$newlink" ]; then
			mv "$link" "$newlink"
			ret=0
		fi
	done

	return $ret
}

# cron was renamed to crond
rename_service cron crond

# keymaps was renamed to loadkmap
rename_service keymaps loadkmap && cat 1>&2 <<-EOF
*
* The OpenRC keymaps service was renamed to loadkmap. You might want
* to rename your previous configuration file /etc/conf.d/keymaps to
* /etc/conf.d/loadkmap. Also make sure that /etc/init.d/keymaps was
* removed and remove it manually if it wasn't.
*
EOF

exit 0

